import { SpecimenEntity } from "@scmt/api-lis-specimen";

export const usePageActions = () => {
  const printingSpecimens = ref<Array<SpecimenEntity>>([]);
  const cancellationSpecimens = ref<Array<SpecimenEntity>>([]);

  const printModelVisible = computed({
    get() {
      return printingSpecimens.value.filter(Boolean).length > 0;
    },
    set(val) {
      !val && (printingSpecimens.value = []);
    },
  });
  const cancellationModelVisible = computed({
    get() {
      return cancellationSpecimens.value.filter(Boolean).length > 0;
    },
    set(val) {
      !val && (cancellationSpecimens.value = []);
    },
  });

  const print = (specimens: SpecimenEntity | SpecimenEntity[]) => {
    printingSpecimens.value = ([] as SpecimenEntity[]).concat(specimens);
  };

  const cancel = (specimens: SpecimenEntity | SpecimenEntity[]) => {
    cancellationSpecimens.value = ([] as SpecimenEntity[]).concat(specimens);
  };

  return {
    printModelVisible,
    printingSpecimens,
    cancellationModelVisible,
    cancellationSpecimens,
    print,
    cancel,
  };
};
